package com.ideaction.datacertify;

import com.alibaba.fastjson.JSONObject;
import com.ideaction.globalconst.Result;
import com.ideaction.log.dblog.RegistLog;
import com.ideaction.utils.GlobalSwitchUtil;

public class SignCertifier extends DataCertifier {
    public static boolean CAN_CERTIFY = true;

    @Override
    public Result dataCertify(JSONObject upData, JSONObject oldData, long passTime, long createTime, String ip) {
        JSONObject oldCommon = oldData.getJSONObject("CommonManager");

        long lastSignTimeStamp = 0;
        if(oldCommon.containsKey("lastSignTime")){
            lastSignTimeStamp = oldCommon.getLong("lastSignTime");
        }

        // 新客户端
        if (lastSignTimeStamp > 0) {
            long dTime = lastSignTimeStamp - System.currentTimeMillis();
            if (dTime > 1000 * 60 * 60 * 24 * 2) {
                return new Result(false);
            }
        }
        return Result.build();
    }

    @Override
    public boolean canCertify(Object... params) {
        return GlobalSwitchUtil.getGlobalSwitch(GlobalSwitchUtil.SIGN_SWITCH);
    }
}
